import { YeeRouter, Ctx, Next } from "src/types"

async function root(ctx: Ctx, next: Next) {
  ctx.body = ctx.success();
}

async function testRequestNumber(ctx: Ctx, next: Next) {
  ctx.body = ctx.success({
    test: ctx.request.body.test
  });
}

async function testId(ctx: Ctx, next: Next) {
  ctx.body = ctx.success({
    id: ctx.params.id
  });
}

async function query(ctx: Ctx, next: Next) {
  console.log(ctx.query);
  ctx.body = ctx.success({
    query: ctx.query,
    body: ctx.request.body
  });
}

async function query2() {

}

export const testRouter: YeeRouter = {
  router: [
    { path: '/', method: 'get', controller: root, auth: false },
    { path: '/query', method: 'get', controller: query, auth: false, 
      query: {
        a: ['number', 2],
        b: ['string', 'ssss'],
      }
    },
    { path: '/query2', method: 'get', controller: query2, auth: false, 
      query: {
        a: ['number', 2, true]
      }
    },
    { path: '/testRequestNumber', method: 'post', 
      body: {
        test: ['number']
      },
      controller: testRequestNumber,
      auth: false
    },
    { path: '/testId/:id', method: 'get', controller: testId, auth: false },
  ]
}